﻿<%@ Page language="vb" CodeFile="printAllInvoice.aspx.vb" Inherits="printAllInvoice_aspx_vb" %>

<%
    rowNumber = 1
    subDo = Request.QueryString("subDo")
    If (Request.QueryString("do")) = Nothing Then
        Over()
        '*************** OVER() gives the menu bar and the logo **************************************
      
        Dim productID
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>PRINT INVOICE<hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='mustafa-test.aspx?subDo=search' method='post'>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Product:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID'>")
        Response.Write("<option value=''> Select product  ")
        dbOpen()
        '******* Calling the products from the tblProduct in the database ******************
        RecSet = Conn.Execute("select productId, product from tblProduct")
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                productID = RecSet.Fields("productID").Value
                product = RecSet.Fields("product").Value
                Response.Write("<option value='" & productID & "'> " & product & " ")
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        '***************  ***********************
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Search'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        '******************** The second block **********************
        '************************************************************
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        
       ' Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
     
        '************* ******************
        Response.Write("<td class='headline' colspan='15'>QUEUED PRINTOUTS - <a href='printAllInvoice.aspx?do=print'>[PRINT ALL]</a><hr class='hrHeadline'></td>")
        Response.Write("</tr>")
        Response.Write("<tr bgcolor='#eeeeee'>")
        Response.Write("<td class='formBold'>Invoice ID</td>")
        Response.Write("<td class='formBold'>References invoice ID</td>")
        Response.Write("<td class='formBold'>Partner</td>")
        Response.Write("<td class='formBold'>Contract number</td>")
        Response.Write("<td class='formBold'>Licence number</td>")
        Response.Write("<td class='formBold'>VIN-number</td>")
        Response.Write("<td class='formBold' align='right'>Invoice amount (Tax incl.)</td>")
        Response.Write("<td class='formBold' align='right'>Invoice claim (Tax incl.)</td>")
        Response.Write("<td class='formBold' align='right'>Invoice date</td>")
        Response.Write("<td class='formBold' align='right'>Expiry date</td>")
        Response.Write("<td class='formBold' align='right'>Days</td>")
        Response.Write("<td class='formBold' align='right'>Invoice printed</td>")
        Response.Write("<td class='formBold' align='right'>Country</td>")
        Response.Write("<td class='formBold' align='right'></td>")
        Response.Write("<td class='formBold' align='right'></td>")
        Response.Write("</tr>")
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, ic.invoiceClaim As invoiceCreditAmount, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoice i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) LEFT JOIN tblInvoiceCredit ic ON ic.invoiceID = i.invoiceID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                invoiceCreditAmount = RecSet.Fields("invoiceCreditAmount").Value
                salesTax = RecSet.Fields("salesTax").Value
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                If IsDBNull(invoiceCreditAmount) = False Then
                    invoiceAmount = CDbl(invoiceAmount) - CDbl(invoiceCreditAmount)
                    invoiceClaim = CDbl(invoiceClaim) - CDbl(invoiceCreditAmount)
                End If
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End If
                If CInt(invoicePrinted) = 0 Then
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End If
                If rowNumber = 0 Then
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End If
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoice.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoice.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End If
        RecSet.Close()
        RecSet = Nothing
        
        
      
       
   
        Under()
    End If
%>



